<?php
require_once 'AutoFileLoader.php';

class AutoLoader  {
	
	static private $basePath = null;
	
	public static function registerAutoLoader ()  {
		self::$basePath = dirname(__FILE__);
		spl_autoload_register(array('AutoLoader', 'load'));
		
// set the basePath for AutoFileLoader
		AutoFileLoader::setBasePath(self::$basePath);
	}
	
	/**
	 * Loads the class if it exists. Therefore all directories where .php files are stored in
	 * will be consulted
	 * @param String $className
	 */
	public static function load ($className)  {
//	All possible directories are stored in $directories
		$directories = array('controller', 'lib', 'model', 'view');
		
		if ($className != '')  {
			$replaced = preg_replace('/_/', '/', $className);
			
			foreach ($directories as $folder)  {
				$combined = self::$basePath. '/'. $folder. '/'. $replaced. '.php';

				if (file_exists($combined))  {
					require_once $combined;
					break;
				}
			}			
			
		}
	}
	
	
	
}

?>